// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj
// jsdoc语法提示教程：https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129
module.exports = {
	_before: function () { // 通用预处理器

	},
	//根据token获取用户手机号码
	getPhoneNumberByToken(event) {
		return uniCloud.getPhoneNumber({
		  	appid: '__UNI__8A62930', // 替换成自己开通一键登录的应用的DCloud appid
		  	provider: 'univerify',
		  	apiKey: 'b9f4ab83ae8c903e259ce649dd3755ca', // 在开发者中心开通服务并获取apiKey
		  	apiSecret: '4104f51fbb00a962580d9b407276ee56', // 在开发者中心开通服务并获取apiSecret
		  	access_token: event.access_token,
		  	openid: event.openid
		  })
	},
	//根据电话号码查询出用户信息
	getUserinfoByMobile(mobile,appid){
		if(mobile){
			const db = uniCloud.databaseForJQL({
			clientInfo: this.getClientInfo()
			});
			return db.collection('uni-id-users').where({mobile:mobile,'register_env.appid':appid}).field('_id,username,nickname,mobile,avatar,status,email,collect,gender,inviter,invite_time').get({getOne:true});
		}else{
			return '手机号码为空';
		}
		
	},
	
	//根据电话号码查询出用户信息
	getUserinfoByOpenid(openid,appid){
		if(openid){
			const db = uniCloud.databaseForJQL({
			clientInfo: this.getClientInfo()
			});
			return db.collection('uni-id-users').where({"wx_openid.app":openid,'register_env.appid':appid}).field('_id,username,wx_openid,wx_unionid,nickname,mobile,avatar,status,email,collect,gender,inviter,register_env,invite_time').get({getOne:true});
		}else{
			return 'openid为空';
		}
		
	},
	
	//根据电话号码查询出用户信息
	getUserinfoByAppleOpenid(openid,appid){
		if(openid){
			const db = uniCloud.databaseForJQL({
			clientInfo: this.getClientInfo()
			});
			return db.collection('uni-id-users').where({"apple_openid":openid,'register_env.appid':appid}).field('_id,username,apple_openid,wx_unionid,nickname,mobile,avatar,status,email,collect,gender,inviter,register_env,invite_time').get({getOne:true});
		}else{
			return 'openid为空';
		}
		
	},
	
	
	//发送短信
	sendSms(tel,code,expMinute=5,templateId='18696'){
		
		    return uniCloud.sendSms({
		      appid: '__UNI__8A62930',
		      smsKey: '976dce0a3dadb0c58fa62dec0b79abe1',
		      smsSecret: 'ec734e60644e2fb7df6f9133bca4c85d',
		      phone: tel,
		      templateId: templateId, // 模板id
		      data: {
		        code: code,
		        expMinute: expMinute,
		      }
		    })
	}
	
}
